<template>
  <div>
    <Echart :options="options" id="distribution24hCcs" height="240px" width="100%"></Echart>
  </div>
</template>

<script>
import Echart from '@/common/echart'
export default {
  data () {
    return {
      options: {},
    };
  },
  components: {
    Echart,
  },
  props: {
    cdata: {
      type: Object,
      default: () => ({})
    },
  },
  watch: {
    cdata: {
      handler (newData) {
        this.options = {
          tooltip: {
            trigger: 'axis',
            backgroundColor: "rgba(255,255,255,0.1)",
            axisPointer: {
              type: 'shadow',
              label: {
                show: true,
                backgroundColor: "#7B7DDC"
              }
            }
          },
          grid: {
            left: '4%',
            right: '4%',
            bottom: '4%',
            containLabel: true
          },
          xAxis: {
            type: 'category',
            data: newData.categories,
            axisLabel: {
              interval: 1, // 强制显示所有标签
              rotate: 0    // 标签旋转角度，可根据需要调整
            },
            axisLine: {
              lineStyle: {
                color: "#B4B4B4"
              }
            },
            axisTick: {
              show: false
            }
          },
          yAxis: {
            type: 'value',
            name: '出车量',
            min: 0,
            // 确保y轴刻度为整数
            axisLabel: {
              formatter: '{value}'
            },
            axisLine: {
              lineStyle: {
                color: "#B4B4B4"
              }
            },
            // 网格线配置
            splitLine: {
              lineStyle: {
                type: 'dashed'
              }
            }
          },
          series: [
            {
              name: '总数',
              type: 'bar',
              data: newData.total,
              // 柱子样式
              itemStyle: {
                normal: {
                  barBorderRadius: 5,
                  color: new this.$echarts.graphic.LinearGradient(0, 0, 0, 1, [
                    { offset: 0, color: "#956FD4" },
                    { offset: 1, color: "#3EACE5" }
                  ])
                }
              },
              // 柱子宽度
              barWidth: 12,
              barGap: "-100%",
              // 显示数值标签
              label: {
                show: true, // 开启显示
                position: 'top', // 数值显示在柱子顶部
                formatter: '{c}', // 格式化显示内容，{c}表示数据值
                textStyle: {
                  color: '#FFF' // 数值颜色
                }
              }
            }
          ]
        }
      },
      immediate: true,
      deep: true
    }
  }
};
</script>

<style lang="scss" scoped>
</style>
